package com.eachann.privacypolicy.library

import android.Manifest
import android.content.Context
import android.content.Intent
import android.net.Uri
import androidx.annotation.RequiresPermission

/**
 * created by eachann on 2020/04/14
 * 隐私政策帮助类
 */
object PrivacyPolicyHelper {
    private const val key = "isAgree"
    /**
     * 跳转手机系统浏览器展示隐私政策
     */
    @RequiresPermission(Manifest.permission.INTERNET)
    fun show(context: Context, url: String) {
        context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
    }

    private fun getSharedPreference(context: Context) =
        context.getSharedPreferences("PrivacyPolicy.session", Context.MODE_PRIVATE)

    /**
     * 同意隐私政策,本地保存状态
     */
    fun saveAgree(context: Context) {
        getSharedPreference(context).edit().putBoolean(key, true).apply()
    }

    /**
     * 判断是否同意隐私政策,默认为不同意
     */
    fun isAgree(context: Context) =
        getSharedPreference(context).getBoolean(key, false)
}